/*
 * 文件名: PaymentValidate.java
 * 版    权：  Copyright PingAn Technology All Rights Reserved.
 * 描    述: [该类的简要描述]
 * 创建人: EX-LILI003
 * 创建时间: 2012-3-5
 * 
 * 修改人：
 * 修改时间:
 * 修改内容：[修改内容]
 */
package app.utils;
/**
 * @author EX-LILI003
 * @date 2012-3-5
 * @version [Android PABank C01, @2012-3-5]
 * @description 网上缴费-字段输入验证
 */
public class PaymentValidate {
	
	/**
	 * [通讯缴费，条形码校验]<BR>
	 * 条形码校验只正针对于上海地区
	 * @param value 条形码
	 * @param company 缴费单位
	 * 0为上海电信
	 * 1为上海移动
	 * 2为上海联通
	 * 3为东方有线
	 * @return 金额
	 */
	public static String barcodeCommunication(String value, int company) {
		
		if (value != null && ! value.equals("")) {
			//号码长度校验
			int length = value.length();
			int codeLength = -1;
			switch (company) {
				case 0:
					//电信
					codeLength = 34;
					break;
				case 1:
					//移动
					codeLength = 30;
					break;
				case 2:
					//联通
					codeLength = 34;
					break;
				case 3:
					//东方
					codeLength = 34;
					break;
				default:
					return null;
			}
			
			if (length != codeLength) {
				return null;
			}
			return value.substring(length - 12, length - 2);
		}
		return null;
	}
	
	/**
	 * [条形码校验，水电煤气缴费条形码校验]<BR>
	 * @param value
	 * @param company
	 * @return
	 */
	public static String barcodeLife(String value, String company) {
	
		if (value != null && ! value.equals("")) {
			//号码长度校验
			int length = value.length();
			int codeLength = -1;
			int amountLength = -1;
			if (company.equals("888880002302900")) {
				//市北自来水
				codeLength = 24;
				amountLength = 9;
			} else if (company.equals("888880002102900")) {
				//市南自来水
				codeLength = 24;
				amountLength = 9;
			} else if (company.equals("888880002702900")) {
				//闵行自来水
				codeLength = 24;
				amountLength = 9;
			} else if (company.equals("888880002602900")) {
				//川沙自来水
				codeLength = 24;
				amountLength = 8;
			} else if (company.equals("888880002202900")) {
				//松江自来水
				codeLength = 24;
				amountLength = 10;	
			} else if (company.equals("888880002502900")) {
				//浦东威立雅自来水
				codeLength = 24;
				amountLength = 9;	
			} else if (company.equals("888880001302900")) {
				//市北燃气
				codeLength = 24;
				amountLength = 7;	
			} else if (company.equals("888880001102900")) {
				//大众燃气
				codeLength = 24;
				amountLength = 7;	
			} else if (company.equals("888880001502900")) {
				//浦东燃气
				codeLength = 24;
				amountLength = 7;	
			} else if (company.equals("888880000502900")) {
				//上海电力
				codeLength = 24;
				amountLength = 8;	
			} else {
				return null;
			}
			
			if (length != codeLength) {
				return null;
			}
			return value.substring(length - amountLength - 1, length - 1);
		}
		return null;
	}
}

